/*******************************************************************************
 * @file Logger.cpp
 * Implementation of methods for Logging related classes.
 * 
 * @package Logging.
 * 
 * @author mk
 * @date 28/12/2008 13:50:21
 * @version 0.1
 ******************************************************************************/

#include "Logger.h"
#include "Assert.h"
#include "Logging.h"

#undef TRACE_FUNC
#define TRACE_FUNC(x)

using namespace Logging;

CLogger* Logger::logger_ = NULL;
CFilteredLogger* FilteredLogger::logger_ = NULL;

boost::thread::id Utils::GetCurrentThreadId()
{
	return boost::this_thread::get_id();
}

std::ostream& Logger::Get()
{			
	__ASSERT_POINTER(logger_);
	return logger_->Get();
}

CFilteredLogger::CFilteredLogger(const std::string& path, const LogFilter& filter):
	CLogger(path)
{
	LogFilter::const_iterator it = filter.begin();
	for (; it != filter.end(); it++)
	{
		filter_.push_back(*it);
	}
}

std::ostream& CFilteredLogger::Get(const std::string& level)
{
	LogFilter::const_iterator it = filter_.begin();
	for (; it != filter_.end(); it++)
	{
		if (it->compare(level) == 0)
		{
			return CLogger::Get();
		}
	}
	return nirvana_;
}

std::ostream& FilteredLogger::Get(const std::string& level)
{
	__ASSERT_POINTER(logger_);
	return logger_->Get(level);
}

boost::mutex& FilteredLogger::Mutex()
{
	__ASSERT_POINTER(logger_);
	return logger_->Mutex();
}